<?php
/**
 * Created by PhpStorm.
 * User: L
 * Date: 19.10.20
 * Time: 10:20
 */

namespace App;


use Illuminate\Support\Facades\DB;

class Helper
{

    public static function setConnection($params)
    {
        config(['database.connections.onthefly' => [
            'driver' => $params->driver,
            'host' => $params->host,
            'username' => $params->username,
            'password' => $params->password
        ]]);

        return DB::connection('onthefly');

//        $params = Database::find( 1 );
//        $connection = DatabaseConnection::setConnection($params);
//        $users = $connection->select(...);
    }

    public static function setDataBaseConf($name,$server,$dbName='auth'){
        config(['database.connections.'.$name => [
            'driver' => 'mysql',
            'host' => $server->db_host,
            'port' => $server->db_port,
            'database' => $dbName,
            'username' => $server->db_acc,
            'password' => $server->db_pwd,
            'charset' => 'utf8',
            'collation' => 'utf8_general_ci',
        ]]);
    }

    public static function GetExpansionName($expansion)
    {
        switch ($expansion)
        {
            case 0:
                return "原始版";
            case 1:
                return "TBC";
            case 2:
                return "WLK";
            case 3:
                return "CTM";
            default:
                return "未知版本";
        }
    }

    public static function ChrRaces($id)
    {
        switch ($id)
        {
            case 1:
                return "人类";
            case 2:
                return "兽人";
            case 4:
                return "暗夜精灵";
            case 5:
                return "亡灵";
            case 7:
                return "侏儒";
            case 6:
                return "牛头人";
            case 64:
                return "Gnome";
            case 8:
                return "巨魔";
            case 256:
                return "哥布林";
            case 10:
                return "血精灵";
            case 11:
                return "德莱尼";
            case 3:
                return "矮人";
            default:
                return $id."未知种族";
        }
    }

    public static function GetClass($id)
    {
        switch ($id)
        {
            case 1:
                return "战士";
            case 2:
                return "圣骑士";
            case 3:
                return "猎人";
            case 4:
                return "潜行者";
            case 8:
                return "法师";
            case 5:
                return "牧师";
            case 6:
                return "死亡骑士";
            case 11:
                return "德鲁伊";
            case 9:
                return "术士";
            case 7:
                return "萨满";
            default:
                return $id."未知职业";
        }
    }

    public static function getRandStr($length=32){
//        return 'wowmanage.cn';
        $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $len = strlen($str)-1;
        $randstr = '';
        for ($i=0;$i<$length;$i++) {
            $num=mt_rand(0,$len);
            $randstr .= $str[$num];
        }
        return $randstr;
    }

}
